﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类CommissionRate。
    /// </summary>
    public class CommissionRate
    {
        public CommissionRate()
        { }
        #region  成员方法
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Business.Entity.CommissionRate GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,CityName,CompanyId,CompanyName,BusinessType,HouseProperty,VStandardRate,BStandardRate from M_Commission_Rate ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.CommissionRate model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,CityName,CompanyId,CompanyName,BusinessType,HouseProperty,VStandardRate,BStandardRate ");
            strSql.Append(" FROM M_Commission_Rate ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.CommissionRate> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,CityName,CompanyId,CompanyName,BusinessType,HouseProperty,VStandardRate,BStandardRate ");
            strSql.Append(" FROM M_Commission_Rate ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.CommissionRate> list = new List<Chenxin.Lib.Business.Entity.CommissionRate>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Chenxin.Lib.Business.Entity.CommissionRate ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.CommissionRate model = new Chenxin.Lib.Business.Entity.CommissionRate();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["CityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CityId = new Guid(ojb.ToString());
            }
            model.CityName = dataReader["CityName"].ToString();
            ojb = dataReader["CompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CompanyId = new Guid(ojb.ToString());
            }
            model.CompanyName = dataReader["CompanyName"].ToString();
            ojb = dataReader["BusinessType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BusinessType = (int)ojb;
            }
            ojb = dataReader["HouseProperty"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HouseProperty = (int)ojb;
            }
            ojb = dataReader["VStandardRate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VStandardRate = (decimal)ojb;
            }
            ojb = dataReader["BStandardRate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BStandardRate = (decimal)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}
